import request from '@/utils/request'
import { AxiosPromise, AxiosResponse } from 'axios'
import { ProductsVo } from '@/api/platform/product/types'

enum Api {
  list = '/product/list',
  add = '/product/add',
  edit = '/product/edit',
  delete = '/product/delete',
  changeStatus = '/product/changeStatus',
  optionSelect = '/product/optionSelect',
}

// 获取列表
export const productsList = (data?): AxiosPromise<AxiosResponse<ProductsVo[]>> => {
  return request({
    url: Api.list,
    method: 'post',
    data,
  })
}

// 编辑、保存
export const productSave = (data: ProductsVo) => {
  return request({
    url: !data.id ? Api.add : Api.edit,
    method: 'post',
    data,
  })
}
export const productDelete = (data) => {
  return request({
    url: Api.delete,
    method: 'post',
    data,
  })
}

// 状态修改
export function changeStatus(id: string | number, status: number) {
  const data = {
    id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}

// 获取选择框列表
export const optionSelect = (data: any) => {
  return request({
    url: Api.optionSelect,
    method: 'post',
    data: data,
  })
}
